# coding=utf-8
# 调用百度云api

import base64
import requests


# 将照片base64编码，并返回编码后的字符串
def img_to_base64(img_file):
    with open(img_file, 'rb') as img:
        temp = base64.b64encode(img.read())
        img = temp.decode()
    return img


# 人脸搜索，在人脸库中对比
def face_search(img, token):
    request_url = "https://aip.baidubce.com/rest/2.0/face/v3/search"
    params = "{\"image\":\"" + img + "\",\"image_type\":\"BASE64\",\"group_id_list\":\"test\",\"quality_control\":\"NONE\",\"liveness_control\":\"NONE\"}"
    request_url = request_url + "?access_token=" + token
    headers = {'content-type': 'application/json'}
    response = requests.post(request_url, data=params, headers=headers)
    if response:
        print(response.json())